package com.brkj.course;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import com.brkj.main.R;
import com.brkj.util.ConstAnts;
import com.brkj.util.view.BaseActivity;
import com.dgl.sdk.util.FileCache;
import com.dgl.sdk.view.autoFitWidthImageView.ImageZoomView;

import java.io.File;

/**
 * Created by dgl on 2014/3/31.
 */
public class CourseDetailSingleImageActivity extends BaseActivity {

    private ImageZoomView autoFitImageView;

    private Handler handler = new Handler(){
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);

            String imgUrl = getIntent().getStringExtra("imgUrl");

            File imgFile = new File(ConstAnts.DOWNLOAD_COURSE__DIR, FileCache.urlToFileName(imgUrl));

            if(imgFile.exists()){
                autoFitImageView.show(imgFile);
            }else{
                autoFitImageView.show(imgUrl, ConstAnts.SINGLE_IMG_COURSE_CATCH_DIR,true);
            }

        }
    };
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course_detail_single_img);

        //不显示标题
//        setReturnBtn(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });
//        setTitle("课程内容");

        autoFitImageView = (ImageZoomView) findViewById(R.id.autoImageView);
        //关闭硬件加速  当显示超大图片的时候， 启用硬件加速会显示不了超大图片
        autoFitImageView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

        //延迟100 毫秒显示， 让autoFitImageView 获取大小 以便显示
        handler.sendEmptyMessageDelayed(0, 100);
    }
}
